﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SLBehaviourSystem
{
    public class DataContainer : IDataContainer
    {
        Dictionary<string, string> k2v = new Dictionary<string, string>();

        public void AddData(string key,string value)
        {
            k2v.Add(key, value);
        }

        private string GetData(string key)
        {
            if (k2v.ContainsKey(key))
            {
                return k2v[key];
            }
            return "";
        }

        public Vector3 GetVector3(string key)
        {
            string content = GetData(key);
            Vector3 value = new Vector3();
            string[] values= content.Replace("(", "").Replace(")", "").Split(',');
            value.x = float.Parse(values[0]);
            value.y = float.Parse(values[1]);
            value.z = float.Parse(values[2]);
            return value;
        }

        public float GetFloat(string key)
        {
            string content = GetData(key);
            if (string.IsNullOrEmpty(content))
            {
                return 0;
            }
            return float.Parse(content);
        }

        public int GetInt(string key)
        {
            string content = GetData( key);
            return int.Parse(content);
        }

        public string GetString(string key)
        {
            return GetData(key);
        }

        public string[] GetKeys()
        {
            return k2v.Keys.ToArray();
        }

        public string[] GetValues()
        {
            return k2v.Values.ToArray();
        }
    }
}
